<?php
/*
 * 日志
 */
namespace Log;

class Logs{


	public function __construct() {
        import('Mongodb');
        $this->mongo = \Think\Mongodb::create();
        $this->mongo->selectDatabase('test');
        $this->time = $_SERVER['REQUEST_TIME'];
        $this->host = $_SERVER['HTTP_HOST'];
        $this->agent = $_SERVER['HTTP_USER_AGENT'];
    }

    //登录
    public function login_Log($user,$type){
    	$this->mongo->selectCollection('login');
    	$arr['host'] = $this->host;
    	$arr['time'] = $this->time;
    	$arr['user_agent'] = $this->agent;
    	if($type==1){
    		$arr['user_b'] = $user;	
    	}elseif($type==2){
    		$arr['client_user'] = $user;
    	}
        $result = $this->mongo->insert($arr);
    } 

    //操作
    public function operation_Log($id,$type,$status){
    	$arr['host'] = $this->host;
        $arr['time'] = $this->time;
        $arr['user_agent'] = $this->agent;
    	$arr['user_b'] = $_SESSION['id'];
    	$this->mongo->selectCollection('operation_type');
    	$array = $this->mongo->findAll();
    	$arr['operation'] = $array[$type][0];
    	$arr['id'] = $id;
        $arr['status'] = $status;
        $this->mongo->selectCollection('operation');
        
        $result = $this->mongo->insert($arr);
    }

    public function find($col){
        $this->mongo->selectCollection($col);
        return $this->mongo->findAll();
    }


    public function insert($col,$array){
        $this->mongo->selectCollection($col);
        return $this->mongo->insert($array);
    }


}